﻿using System;
using System.Data;
using VIT.Web.UI;
using VIT.Web.Controls;
using VIT.Provider;
using System.Web.UI.WebControls;

namespace VIT.Web.Admin
{
    public partial class MemberList : VIT.Web.UI.VITComponent
    {
        VIT.Provider.Member obj;
        protected void Page_Load(object sender, EventArgs e)
        {
            obj = new VIT.Provider.Member();  
        }

        #region Methods
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select)]
        public DataTable GetData(string SortColumn)
        {
            DataTable DT = new VIT.Provider.Member().GetAll(SortColumn);
            return new VIT.Provider.Member().GetAll(SortColumn);
        }

        public void DeleteList(string[] listMember)
        {
            foreach (string mem in listMember)
            {
                obj.Delete(mem);
            }
        }

        public void LockList(string[] listId, bool status)
        {
            foreach (string id in listId)
                obj.Lock(id, status);
        }
        #endregion

        #region Events
        protected void Lock_Click(object sender, EventArgs e)
        {
            string[] list = Request["itemCheckbox"].Split(',');
            LockList(list, true);
            ListView.DataBind();
        }

        protected void Unlock_Click(object sender, EventArgs e)
        {
            string[] list = Request["itemCheckbox"].Split(',');
            LockList(list, false);
            ListView.DataBind();
        }

        protected void changeStatus_Click(object sender, EventArgs e)
        {
            LinkSubmit btn = (LinkSubmit)sender;
            string p = btn.Param.ToString();

            string[] id = p.Split('|');
            bool status = Convert.ToBoolean(id[1]);
            obj.Lock(id[0],!status);
            ListView.DataBind();
        }

        protected void changeActiveCode_Click(object sender, EventArgs e)
        {
            LinkSubmit btn = (LinkSubmit)sender;
            string p = btn.Param.ToString();
            obj.Active(p);
        }

        protected void Delete_Click(object sender, EventArgs e)
        {
            string[] check = Request["itemCheckbox"].Split(',');
            DeleteList(check);
        }

        protected void Insert_Click(object sender, EventArgs e)
        {
            TransferComponent("Member", "MemberInfo");
        }

        protected void Pager_PreRender(object sender, EventArgs e)
        {
            ListView.DataBind();
        }
        #endregion
    }
}
